package client;


import java.io.IOException;

import java.rmi.*;
import java.util.Vector;

/*
 * Author: David Swords
 * Email: davidswordster@gmail.com
 * Skype: masterexploder1985
 * 
 * The implementation of the device that will select a song.
 */

public class Remote
{
	private Vector<String[]> songList;
	private ClientImpl client;
	
	public Remote() throws IOException{
		songList = new Vector<String[]>();
		client = new ClientImpl();
	}
	
	@SuppressWarnings("deprecation")
	public Vector<String[]> getListOfSongs() throws RemoteException{
		songList = client.SERVER.listOfSongs();
		/*
		System.out.println("Remote.");
		for(int i=0;i<songList.size();i++){
			for(int j=0;j<songList.get(i).length;j++)
				System.out.println(songList.get(i)[j]);
		}
		*/
		return client.SERVER.listOfSongs();
	}
	
	public Vector<String[]> getPlayList() throws RemoteException{
		songList = client.SERVER.listOfSongs();
		/*
		System.out.println("Remote.");
		for(int i=0;i<songList.size();i++){
			for(int j=0;j<songList.get(i).length;j++)
				System.out.println(songList.get(i)[j]);
		}
		*/
		return client.SERVER.listOfSongs();
	}
	
	public int getNumberOfSongs(){
		int count = songList.size();
		if(count==0){
			System.out.println("It appears that no songs are available at the moment.");
			return 0;
		}
		else
			return count;
	}
	
	public void connectToService(String servicetype) throws IOException, InterruptedException{
		client.connectToService(servicetype);
	}
	
	public boolean selectSong(String[] song) throws RemoteException{
		return client.SERVER.addSongToPlaylist(song);
	}
	
	public boolean removeSong(String[] song) throws RemoteException{
		return client.SERVER.removeSongToPlaylist(song);
	}
	
	public void showHandshaking(boolean b){
		client.setHandshaking(b);
	}
	
	public boolean isConnected() throws InterruptedException{
		return client.isConnected();
	}
	
	public String handShake(){
		return client.handShake();
	}
}
